﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using QLCONGNOLIBS.Controllers;
using QLCONGNOLIBS.Securities;
using System.Data.SqlClient;
using QLCONGNOAPPs.UserForms.Customers;


namespace QLCONGNOAPPs.UserControls.Customers
{
    public partial class ucCustomers : UserControl
    {
        private SqlConnection m_objConnection;
        private SecurityEntity m_objSecurity;
        private CustomerControllers m_objCusController;

        public ucCustomers(SqlConnection objConnection, SecurityEntity objSecurity)
        {
            InitializeComponent();
            this.Dock = DockStyle.Fill;
            ucBaseControl1.PressNew += new EventHandler(ucBaseControl1_PressNew);
            ucBaseControl1.PressEdit += new EventHandler(ucBaseControl1_PressEdit);
            ucBaseControl1.PressDelete += new EventHandler(ucBaseControl1_PressDelete);
            ucBaseControl1.PressClose += new EventHandler(ucBaseControl1_PressClose);
            m_objConnection = objConnection;
            m_objSecurity = objSecurity;
            m_objCusController = new CustomerControllers(m_objConnection, m_objSecurity);
            LoadCustomers();
        }

        void ucBaseControl1_PressClose(object sender, EventArgs e)
        {
            throw new NotImplementedException();
        }
        void ucBaseControl1_PressDelete(object sender, EventArgs e)
        {
            throw new NotImplementedException();
        }

        void ucBaseControl1_PressEdit(object sender, EventArgs e)
        {
            
        }

        void ucBaseControl1_PressNew(object sender, EventArgs e)
        {
            frmCustomerDetails frm = new frmCustomerDetails(m_objConnection, m_objSecurity);
            frm.ShowDialog();
        }

        private void LoadCustomers()
        {
            try
            {
                this.Cursor = Cursors.WaitCursor;
                if (m_objCusController==null)              
                    m_objCusController = new CustomerControllers(m_objConnection, m_objSecurity);
                grdCCustomers.DataSource = m_objCusController.getCustomers();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }

        private void grdVCustomers_DoubleClick(object sender, EventArgs e)
        {
            MessageBox.Show("sdsdsd","sdsdsd");
        }
    }
}
